# Definition for singly-linked list.
#class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    # @param {ListNode} l1
    # @param {ListNode} l2
    # @return {ListNode}
    def addTwoNumbers(self, l1, l2):
        lheader = None
        lnext = None
        left = 0

        while l1 != None or l2 != None:
            ln = ListNode(left)

            if l1 != None:
                ln.val += l1.val
                l1 = l1.next

            if l2 != None:
                ln.val += l2.val
                l2 = l2.next

            left = ln.val / 10
            ln.val = ln.val % 10

            if not lheader:
                lheader = ln
                lnext = ln
            else:
                lnext.next = ln
                lnext = ln

        if left:
            lnext.next = ListNode(left)

        return lheader
